import axios from 'axios'
import JSBridge from './JSBridge'
import './Authorization'

let YSModule = {}
const jsBridge = JSBridge.getInstance()

YSModule.install = function (Vue, options) {
  Vue.config.productionTip = false
  Vue.prototype.axios = axios
  Vue.prototype.jsBridge = jsBridge
  Vue.prototype.domain = 'http://' + window.location.host + '/#/'

  Vue.prototype.pushToRoute = function (data) {
    if (!data) {
      return
    }
    if (data.scheme) {
      console.log(data.data)
      this.$router.push({
        name: data.name,
        params: data.data ? data.data : {}
      })
    } else {
      this.$router.push({
        name: 'error',
        params: {
          message: '打开原生功能:' + data.title,
          tip: data.route
        }
      })
    }
  }

  Vue.prototype.pushWeblink = function (data) {
    if (!data) {
      return
    }
    if (data.scheme) {
      console.log(data.data)
      this.$router.push({
        name: data.name,
        params: data.data ? data.data : {}
      })
    } else {
      this.$router.push({
        name: 'error',
        params: {
          message: '打开原生功能:' + data.title,
          tip: data.route
        }
      })
    }
  }

  // jsBridge.toast = Vue.toast

  // 给iOS监听请求完成
  jsBridge.finishLoaded(null)
}

export default YSModule
